package com.chenfan.magic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenfan.magic.base.R;
import com.chenfan.magic.base.S;
import com.chenfan.magic.dao.DatasourceTypeMapper;
import com.chenfan.magic.entity.IdcDatasourceType;
import com.chenfan.magic.service.IDatasourceTypeService;
import com.chenfan.magic.utils.StringKit;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 服务实现类
 *
 * @author troy
 */
@Service
@AllArgsConstructor
public class DatasourceTypeServiceImpl extends ServiceImpl<DatasourceTypeMapper, IdcDatasourceType> implements IDatasourceTypeService {

    @Override
    public R get(String datasourceTypeId) {
        if (StringKit.isBlank(datasourceTypeId)) {
            return S.fail(S.IDC_DATASOURCE_TYPE_CODE_NULL);
        }
        IdcDatasourceType idcDatasourceType = this.getById(datasourceTypeId);
        if (idcDatasourceType == null) {
            return S.fail(S.IDC_DATASOURCE_TYPE_UNSUPPORT);
        } else {
            if (0 == idcDatasourceType.getStatus()) {
                return R.success().put(idcDatasourceType);
            } else if (1 == idcDatasourceType.getStatus()) {
                return S.fail(S.IDC_DATASOURCE_TYPE_FORBIDDEN);
            } else {
                return S.fail(S.IDC_DATASOURCE_TYPE_SUPPORT_STOP);
            }
        }
    }
}
